package components.dialogs.adjustments
{
	import UIFree.uif_component;
	
	import UIUtils.uif_color;
	import UIUtils.uif_util;
	
	import classes.Commands.c_applyTextParams;
	
	import components.dialogs.c_elementPropDlg;
	import components.dialogs.c_propertyDialog;
	import components.editor.c_baseElement;
	import components.editor.c_textElement;
	
	import flash.events.Event;
	import flash.text.TextFormat;
	
	public class c_Text extends c_elementPropDlg {
		private var _prevParams: Object;
		public function c_Text(parent:uif_component, a_element:c_baseElement, a_title:String='', modal:Boolean=false, canClose:int=2) {
			var te: c_textElement = a_element as c_textElement;
			var aItems: Array = [
				{
					caption: 'impact',
					font: 'impact'
				},{
					caption: 'a_algeriusbrk',
					font: 'a_algeriusbrk'
				},{
					caption: 'b074000d',
					font: 'b074000d'
				},{
					caption: 'comic',
					font: 'comic'
				},{
					caption: 'Ekaterina',
					font: 'Ekaterina'
				},{
					caption: 'EkaterinaTwo',
					font: 'EkaterinaTwo'
				},{
					caption: 'GARA',
					font: 'GARA'
				},{
					caption: 'GOTHIC',
					font: 'GOTHIC'
				},{
					caption: 'MTCORSVA',
					font: 'MTCORSVA'
				},{
					caption: 'times',
					font: 'times'
				}
			];
			var tf: TextFormat = te.getTextFormat();
			_prevParams = {
				font	: tf.font,
				color	: tf.color
			}
			var rgb: Array = uif_color.uintToRGBA(_prevParams.color as uint);
			super(parent, a_element, [{
				title	: 'Цвет текста',
				type	: c_propertyDialog.PTYPE_COLORBALANCE,
				value	: {
					red		: rgb[1] / 0x7F - 1,
					green	: rgb[2] / 0x7F - 1,
					blue	: rgb[3] / 0x7F - 1
				}
			},{
				title	: 'Шрифт',
				type	: c_propertyDialog.PTYPE_COMBO,
				value	: uif_util.indexOf(aItems, _prevParams.font, 'font'),
				items	: aItems
			}], a_title, modal, canClose);
		}
		
		protected function get textComponent(): c_textElement {
			return super.element as c_textElement;
		}
		
		protected function cValue(aValue: Number): uint {
			return (aValue + 1) * 0x7F;
		}
		
		override protected function updateElement(): void {
			textComponent.applyTextFormat(null, getParams());
		}
		
		protected function getParams(): Object {
			return {
				font	: values[1].value.font,
				color	: uif_color.RGB(cValue(values[0].value.red), cValue(values[0].value.green), cValue(values[0].value.blue))  
			}
		}
		
		override protected function doCancel(): void {
			textComponent.applyTextFormat(null, _prevParams);
		}
		
		override protected function doApply():void {
			executeCommand(new c_applyTextParams(textComponent, getParams(), _prevParams));
		}		
	}
}